	PRESERVE8

	IMPORT Main
	IMPORT HandleIRQ
	IMPORT OSCtxSw
	IMPORT OSTickISR
	IMPORT OSTCBCur
	IMPORT OSIntNesting
	IMPORT OSIntStk

	EXPORT DELAY
	EXPORT BEEP
	EXPORT BEEPOFF
;-----------------------------------------------------------------------------------------------------------------------------
BK_IRQ			RLIST {R0-R12,LR}
RE_IRQ			RLIST {R0-R12,PC}
BK_FIQ			RLIST {R0-R7,LR}
BK_APCS			RLIST {R4-R11}
  
MAX_SWINUM		EQU 7

_STACKBASEADDR	EQU 0x32000000
rBWSCON			EQU 0x48000000
rSRCPND			EQU 0X4A000000
rINTMOD			EQU 0X4A000004
rINTMSK			EQU 0X4A000008
rINTPND			EQU 0x4A000010
rINTOFFSET		EQU 0x4A000014
rSUBSRCPND		EQU 0x4A000018
rINTSUBMSK		EQU 0X4A00001C
rLOCKTIME		EQU 0x4C000000
rMPLLCON		EQU 0x4C000004
rUPLLCON		EQU 0x4C000008
rCLKDIVN		EQU 0x4C000014
rULCON0			EQU 0x50000000
rUCON0			EQU 0x50000004
rUFCON0			EQU 0x50000008
rUMCON0			EQU 0x5000000C
rUBRDIV0		EQU 0x50000028
rUTXH0			EQU 0x50000023
rURXH0			EQU 0x50000027
rULCON1			EQU 0x50004000
rUCON1			EQU 0x50004004
rUFCON1			EQU 0x50004008
rUMCON1			EQU 0x5000400C
rUBRDIV1		EQU 0x50004028
rUTXH1			EQU 0x50004023
rURXH1			EQU 0x50004027
rWTCON			EQU 0x53000000
rGPBCON			EQU 0x56000010
rGPBDAT			EQU 0x56000014
rGPGCON			EQU 0x56000060
rGPGUP			EQU 0x56000068
rGPHCON			EQU 0x56000070
rGPHDAT			EQU 0x56000074
rGPHUP			EQU 0x56000078
rEINTMASK		EQU 0x560000A4
rEINTPEND		EQU 0x560000A8


B1_BWCON		EQU 2_0010
B2_BWCON		EQU 2_0001
B3_BWCON		EQU 2_0001
B4_BWCON		EQU 2_0001
B5_BWCON		EQU 2_0001
B6_BWCON		EQU 2_0010
B7_BWCON		EQU 2_0010


U_MDIV			EQU 0x38	  ;M/P/S DIV FOR UPLL,for more see chapter"PLL VALUE TABLE" in 2440datasheet
U_PDIV			EQU	0x2		  ;UPLL = 48.00MHz
U_SDIV			EQU	0x2

M_MDIV			EQU 0x7f	  ;M/P/S DIV FOR MPLL,for more see chapter"PLL VALUE TABLE" in 2440datasheet
M_PDIV			EQU	0x2		  ;MPLL = 405.00MHz
M_SDIV			EQU	0x1


USRMODE			EQU 0x10
FIQMODE			EQU 0x11
IRQMODE			EQU 0x12
SVCMODE			EQU 0x13
ABTMODE			EQU 0x17
UNDMODE			EQU 0x1B
SYSMODE			EQU 0x1F


IRQMSK			EQU 0x80
FIQMSK			EQU 0x40
NOINT			EQU 0xC0


StackUse		EQU (_STACKBASEADDR-0X3800)
StackSvc		EQU (_STACKBASEADDR-0x2800)
StackUnd		EQU (_STACKBASEADDR-0x2400)
StackAbt		EQU (_STACKBASEADDR-0x2000)
StackIrq		EQU (_STACKBASEADDR-0x1000)
StackFiq		EQU (_STACKBASEADDR-0x0)


OS_IntStkSIZE	EQU 100
OS_StkItemSIZE	EQU 4
;-----------------------------------------------------------------------------------------------------------------------------
	CODE32
	AREA	Init,CODE,READONLY,ALIGN=2

BEEP
	STMDB SP!,{R0,R1,R2,LR}			  ;STMFD
	MOV R2,R0
BEEP_LOOP
	BL BEEPON
	MOV R0,R2
	BL DELAY
	BL BEEPOFF
	MOV R0,R2
	BL DELAY
	BL BEEPON
	MOV R0,R2
	BL DELAY
	BL BEEPOFF
	MOV R0,R2
	BL DELAY
	BL BEEPON
	MOV R0,R2
	BL DELAY
	BL BEEPOFF
	MOV R0,R2
	BL DELAY
	BL BEEPON
	MOV R0,R2
	BL DELAY
	BL BEEPOFF
	MOV R0,R2
	BL DELAY
	SUBS R1,R1,#1
	BPL BEEP_LOOP
	LDMIA SP!,{R0,R1,R2,LR}		 ;LDMFD
	MOVS PC,LR
;-----------------------------------------------------------------------------------------------------------------------------
DELAY
	SUBS R0,R0,#1
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	BPL DELAY
	MOVS PC,LR
;-----------------------------------------------------------------------------------------------------------------------------
BEEPON
	STMDB SP!,{R0,R1}		 ;STMFD
	LDR R0,=rGPBDAT
	LDR R1,=(((0<<4):OR:(0<<3):OR:(0<<2):OR:(0<<1))<<4):OR:1  ; LED:4 3 2 1	BEEP
	STR R1,[R0]
	LDMIA SP!,{R0,R1}		 ;LDMFD
	MOVS PC,LR
BEEPOFF						
	STMDB SP!,{R0,R1}	     ;STMFD
	LDR R0,=rGPBDAT
	LDR R1,=(((1<<4):OR:(1<<3):OR:(1<<2):OR:(1<<1))<<4):OR:0  ; LED:4 3 2 1	BEEP
	STR R1,[R0]
	LDMIA SP!,{R0,R1}		 ;LDMFD
	MOVS PC,LR
;-----------------------------------------------------------------------------------------------------------------------------		  
	END